﻿@using thousandClear.Areas.Admin.Models;
@model AddressModel

@section Styles{
    @Styles.Render("~/cssbundles/shop/order")
}


@section Scripts{
    @Scripts.Render("~/jsbundles/shop/order")

    <script>

        function onBridgeReady(){

            var orderID=@Model.DATIDdesc;

            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId": "@ViewBag.AppId",     //公众号名称，由商户传入
                    "timeStamp":"@ViewBag.TimeStamp",         //时间戳，自1970年以来的秒数
                    "nonceStr" : "@ViewBag.NonceStr", //随机串
                    "package" : "@ViewBag.Package",
                    "signType" : "MD5",         //微信签名方式：
                    "paySign": "@ViewBag.Paysign" //微信签名
                },
                function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {

                        onSuccess();
                        window.location.replace("../Order/List?n=2&openid=@ViewBag.OpenId");
                        @*$.ajax({
                            type: "get",
                            url: "../Order/change/" + orderID,
                            contentType: "application/json",
                            success: function (data) {
                                window.location.replace("../Order/List?n=2&openid=@ViewBag.OpenId");
                            },
                            error:function(a,b){
                                alert(a.status);
                            }

                        })*@

                    }// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                }
            );
        }
        function showError(msg){
            swal({
                title: "",
                text: msg,
                type: "error",
                showConfirmButton: false,
                showCancelButton: false,
                timer: 2000,
            });
        }
        function onSuccess() {
            swal({
                title: "支付成功",
                text: "正在返回我的订单...",
                type: "success",
                showConfirmButton: false,
                showCancelButton: false,
            })
        }

        (function(){
            console.log(@ViewBag.Vail);
            if(@ViewBag.Vail=="-1")
            {
                alert('此订单时间已被预约，请重新下单');
                window.location.replace("../Order/List?n=2&openid=@ViewBag.OpenId");
                return;
            }

            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            }else{
                onBridgeReady();
            }
        }())



    </script>
}
